#!/usr/bin/env python3.3

#
#  Filename: e27.py
#  Author  : lukas singer
#
#  Comment : Created by createSolution.sh
#

#import euler
from euler import isPrime, primeSieve

def countPrimes(a,b):
  n=0
  while isPrime(n*n+a*n+b):
    n+=1
  return n

def pe27():
  x=0
  c=0
  p=primeSieve(1000)
  for a in p:
    for b in p:
      cx=countPrimes(a,b)
      if cx>c:
        c=cx
        x=a*b
      cx=countPrimes(a,-b)
      if cx>c:
        c=cx
        x=a*-b
      cx=countPrimes(-a,b)
      if cx>c:
        c=cx
        x=-a*b
      cx=countPrimes(-a,-b)
      if cx>c:
        c=cx
        x=-a*-b
  print(x)

if __name__=="__main__":
  pe27()

